LIST(APPEND cleanup_list
        gldcore/build.h
        gldcore/config.h
        gldcore/gridlabd.sh
        gldcore/gridlabd-aggregate.o
        gldcore/gridlabd-class.o
        gldcore/gridlabd-cmdarg.o
        gldcore/gridlabd-compare.o
        gldcore/gridlabd-convert.o
        gldcore/gridlabd-debug.o
        gldcore/gridlabd-deltamode.o
        gldcore/gridlabd-enduse.o
        gldcore/gridlabd-environment.o
        gldcore/gridlabd-exception.o
        gldcore/gridlabd-exec.o
        gldcore/gridlabd-find.o
        gldcore/gridlabd-globals.o
        gldcore/gridlabd-gui.o
        gldcore/gridlabd-http_client.o
        gldcore/gridlabd-index.o
        gldcore/gridlabd-instance.o
        gldcore/gridlabd-instance_cnx.o
        gldcore/gridlabd-instance_slave.o
        gldcore/gridlabd-interpolate.o
        gldcore/gridlabd-job.o
        gldcore/gridlabd-kill.o
        gldcore/gridlabd-kml.o
        gldcore/gridlabd-legal.o
        gldcore/gridlabd-linkage.o
        gldcore/gridlabd-link.o
        gldcore/gridlabd-list.o
        gldcore/gridlabd-load.o
        gldcore/gridlabd-loadshape.o
        gldcore/gridlabd-load_xml.o
        gldcore/gridlabd-load_xml_handle.o
        gldcore/gridlabd-local.o
        gldcore/gridlabd-lock.o
        gldcore/gridlabd-main.o
        gldcore/gridlabd-match.o
        gldcore/gridlabd-matlab.o
        gldcore/gridlabd-module.o
        gldcore/gridlabd-object.o
        gldcore/gridlabd-output.o
        gldcore/gridlabd-property.o
        gldcore/gridlabd-random.o
        gldcore/gridlabd-realtime.o
        gldcore/gridlabd-sanitize.o
        gldcore/gridlabd-save.o
        gldcore/gridlabd-schedule.o
        gldcore/gridlabd-server.o
        gldcore/gridlabd-setup.o
        gldcore/gridlabd-stream.o
        gldcore/gridlabd-test.o
        gldcore/gridlabd-test_framework.o
        gldcore/gridlabd-threadpool.o
        gldcore/gridlabd-timestamp.o
        gldcore/gridlabd-transform.o
        gldcore/gridlabd-unit.o
        gldcore/gridlabd-validate.o
        gldcore/gridlabd-version.o
        third_party/CBLAS/superLU_MT_libsuperlu_la-dasum.lo
        third_party/CBLAS/superLU_MT_libsuperlu_la-daxpy.lo
        third_party/CBLAS/superLU_MT_libsuperlu_la-dcopy.lo
        third_party/CBLAS/superLU_MT_libsuperlu_la-ddot.lo
        third_party/CBLAS/superLU_MT_libsuperlu_la-dgemv.lo
        third_party/CBLAS/superLU_MT_libsuperlu_la-dger.lo
        third_party/CBLAS/superLU_MT_libsuperlu_la-dnrm2.lo
        third_party/CBLAS/superLU_MT_libsuperlu_la-drot.lo
        third_party/CBLAS/superLU_MT_libsuperlu_la-dscal.lo
        third_party/CBLAS/superLU_MT_libsuperlu_la-dsymv.lo
        third_party/CBLAS/superLU_MT_libsuperlu_la-dsyr2.lo
        third_party/CBLAS/superLU_MT_libsuperlu_la-dtrsv.lo
        third_party/CBLAS/superLU_MT_libsuperlu_la-idamax.lo
        third_party/superLU_MT/libsuperlu_la-await.lo
        third_party/superLU_MT/libsuperlu_la-colamd.lo
        third_party/superLU_MT/libsuperlu_la-dclock.lo
        third_party/superLU_MT/libsuperlu_la-dgscon.lo
        third_party/superLU_MT/libsuperlu_la-dgsequ.lo
        third_party/superLU_MT/libsuperlu_la-dgsrfs.lo
        third_party/superLU_MT/libsuperlu_la-dgstrs.lo
        third_party/superLU_MT/libsuperlu_la-dlacon.lo
        third_party/superLU_MT/libsuperlu_la-dlamch.lo
        third_party/superLU_MT/libsuperlu_la-dlangs.lo
        third_party/superLU_MT/libsuperlu_la-dlaqgs.lo
        third_party/superLU_MT/libsuperlu_la-dmatgen.lo
        third_party/superLU_MT/libsuperlu_la-dmyblas2.lo
        third_party/superLU_MT/libsuperlu_la-dpivotgrowth.lo
        third_party/superLU_MT/libsuperlu_la-dreadhb.lo
        third_party/superLU_MT/libsuperlu_la-dsp_blas2.lo
        third_party/superLU_MT/libsuperlu_la-dsp_blas3.lo
        third_party/superLU_MT/libsuperlu_la-get_perm_c.lo
        third_party/superLU_MT/libsuperlu_la-heap_relax_snode.lo
        third_party/superLU_MT/libsuperlu_la-lsame.lo
        third_party/superLU_MT/libsuperlu_la-mmd.lo
        third_party/superLU_MT/libsuperlu_la-pdgssv.lo
        third_party/superLU_MT/libsuperlu_la-pdgssvx.lo
        third_party/superLU_MT/libsuperlu_la-pdgstrf_bmod1D.lo
        third_party/superLU_MT/libsuperlu_la-pdgstrf_bmod1D_mv2.lo
        third_party/superLU_MT/libsuperlu_la-pdgstrf_bmod2D.lo
        third_party/superLU_MT/libsuperlu_la-pdgstrf_bmod2D_mv2.lo
        third_party/superLU_MT/libsuperlu_la-pdgstrf.lo
        third_party/superLU_MT/libsuperlu_la-pdgstrf_column_bmod.lo
        third_party/superLU_MT/libsuperlu_la-pdgstrf_column_dfs.lo
        third_party/superLU_MT/libsuperlu_la-pdgstrf_copy_to_ucol.lo
        third_party/superLU_MT/libsuperlu_la-pdgstrf_factor_snode.lo
        third_party/superLU_MT/libsuperlu_la-pdgstrf_init.lo
        third_party/superLU_MT/libsuperlu_la-pdgstrf_panel_bmod.lo
        third_party/superLU_MT/libsuperlu_la-pdgstrf_panel_dfs.lo
        third_party/superLU_MT/libsuperlu_la-pdgstrf_pivotL.lo
        third_party/superLU_MT/libsuperlu_la-pdgstrf_snode_bmod.lo
        third_party/superLU_MT/libsuperlu_la-pdgstrf_snode_dfs.lo
        third_party/superLU_MT/libsuperlu_la-pdgstrf_thread.lo
        third_party/superLU_MT/libsuperlu_la-pdgstrf_thread_finalize.lo
        third_party/superLU_MT/libsuperlu_la-pdgstrf_thread_init.lo
        third_party/superLU_MT/libsuperlu_la-pdmemory.lo
        third_party/superLU_MT/libsuperlu_la-pdutil.lo
        third_party/superLU_MT/libsuperlu_la-pmemory.lo
        third_party/superLU_MT/libsuperlu_la-pxgstrf_finalize.lo
        third_party/superLU_MT/libsuperlu_la-pxgstrf_mark_busy_descends.lo
        third_party/superLU_MT/libsuperlu_la-pxgstrf_pruneL.lo
        third_party/superLU_MT/libsuperlu_la-pxgstrf_relax_snode.lo
        third_party/superLU_MT/libsuperlu_la-pxgstrf_scheduler.lo
        third_party/superLU_MT/libsuperlu_la-pxgstrf_super_bnd_dfs.lo
        third_party/superLU_MT/libsuperlu_la-pxgstrf_synch.lo
        third_party/superLU_MT/libsuperlu_la-qrnzcnt.lo
        third_party/superLU_MT/libsuperlu_la-sp_coletree.lo
        third_party/superLU_MT/libsuperlu_la-sp_colorder.lo
        third_party/superLU_MT/libsuperlu_la-cholnzcnt.lo
        third_party/superLU_MT/libsuperlu_la-sp_ienv.lo
        third_party/superLU_MT/libsuperlu_la-superlu_timer.lo
        third_party/superLU_MT/libsuperlu_la-util.lo
        third_party/superLU_MT/libsuperlu_la-xerbla.lo
        third_party/jsonCpp/libjsoncpp_la-jsoncpp.lo
        assert/assert_la-assert.lo
        assert/assert_la-complex_assert.lo
        assert/assert_la-double_assert.lo
        assert/assert_la-enum_assert.lo
        assert/assert_la-int_assert.lo
        assert/assert_la-init.lo
        assert/assert_la-main.lo
        climate/climate_la-climate.lo
        climate/climate_la-csv_reader.lo
        climate/climate_la-init.lo
        climate/climate_la-main.lo
        climate/climate_la-solar_angles.lo
        climate/climate_la-test.lo
        climate/climate_la-weather.lo
        climate/climate_la-weather_reader.lo
        commercial/commercial_la-hvac.lo
        commercial/commercial_la-init.lo
        commercial/commercial_la-main.lo
        commercial/commercial_la-multizone.lo
        commercial/commercial_la-office.lo
        commercial/commercial_la-solvers.lo
        connection/connection_la-connection.lo
        connection/connection_la-socket.lo
        connection/connection_la-server.lo
        connection/connection_la-cache.lo
        connection/connection_la-client.lo
        connection/connection_la-native.lo
        connection/connection_la-tcp.lo
        connection/connection_la-udp.lo
        connection/connection_la-xml.lo
        connection/connection_la-json.lo
        connection/connection_la-transport.lo
        connection/connection_la-varmap.lo
        connection/connection_la-init.lo
        connection/connection_la-main.lo
        gldcore/link/engine/glxengine_la-engine.lo
        gldcore/link/engine/glxengine_la-udpconnection.lo
        gldcore/link/matlab/glxmatlab_la-matlab.lo
        gldcore/solvers/glsolvers_la-etp.lo
        gldcore/solvers/glsolvers_la-main.lo
        gldcore/solvers/glsolvers_la-modified_euler.lo
        generators/generators_la-battery.lo
        generators/generators_la-central_dg_control.lo
        generators/generators_la-diesel_dg.lo
        generators/generators_la-energy_storage.lo
        generators/generators_la-init.lo
        generators/generators_la-inverter.lo
        generators/generators_la-inverter_dyn.lo
        generators/generators_la-main.lo
        generators/generators_la-rectifier.lo
        generators/generators_la-solar.lo
        generators/generators_la-windturb_dg.lo
        generators/generators_la-controller_dg.lo
        market/market_la-auction.lo
        market/market_la-bid.lo
        market/market_la-collect.lo
        market/market_la-controller.lo
        market/market_la-curve.lo
        market/market_la-double_controller.lo
        market/market_la-generator_controller.lo
        market/market_la-init.lo
        market/market_la-main.lo
        market/market_la-passive_controller.lo
        market/market_la-stub_bidder.lo
        market/market_la-stubauction.lo
        market/market_la-supervisory_control.lo
        mysql/mysql_la-collector.lo
        mysql/mysql_la-database.lo
        mysql/mysql_la-init.lo
        mysql/mysql_la-main.lo
        mysql/mysql_la-player.lo
        mysql/mysql_la-recorder.lo
        mysql/mysql_la-table_manager.lo
        mysql/mysql_la-query_engine.lo
        mysql/mysql_la-group_recorder.lo
        optimize/optimize_la-init.lo
        optimize/optimize_la-main.lo
        optimize/optimize_la-simple.lo
        powerflow/powerflow_la-billdump.lo
        powerflow/powerflow_la-capacitor.lo
        powerflow/powerflow_la-currdump.lo
        powerflow/powerflow_la-emissions.lo
        powerflow/powerflow_la-fault_check.lo
        powerflow/powerflow_la-fuse.lo
        powerflow/powerflow_la-impedance_dump.lo
        powerflow/powerflow_la-jsondump.lo
        powerflow/powerflow_la-init.lo
        powerflow/powerflow_la-line_configuration.lo
        powerflow/powerflow_la-line.lo
        powerflow/powerflow_la-line_spacing.lo
        powerflow/powerflow_la-link.lo
        powerflow/powerflow_la-load.lo
        powerflow/powerflow_la-load_tracker.lo
        powerflow/powerflow_la-main.lo
        powerflow/powerflow_la-meter.lo
        powerflow/powerflow_la-motor.lo
        powerflow/powerflow_la-performance_motor.lo
        powerflow/powerflow_la-node.lo
        powerflow/powerflow_la-overhead_line_conductor.lo
        powerflow/powerflow_la-overhead_line.lo
        powerflow/powerflow_la-powerflow.lo
        powerflow/powerflow_la-powerflow_library.lo
        powerflow/powerflow_la-powerflow_object.lo
        powerflow/powerflow_la-power_metrics.lo
        powerflow/powerflow_la-pqload.lo
        powerflow/powerflow_la-recloser.lo
        powerflow/powerflow_la-regulator_configuration.lo
        powerflow/powerflow_la-regulator.lo
        powerflow/powerflow_la-restoration.lo
        powerflow/powerflow_la-sectionalizer.lo
        powerflow/powerflow_la-series_reactor.lo
        powerflow/powerflow_la-solver_nr.lo
        powerflow/powerflow_la-sync_check.lo
        powerflow/powerflow_la-substation.lo
        powerflow/powerflow_la-switch_object.lo
        powerflow/powerflow_la-test.lo
        powerflow/powerflow_la-transformer_configuration.lo
        powerflow/powerflow_la-transformer.lo
        powerflow/powerflow_la-triplex_line_conductor.lo
        powerflow/powerflow_la-triplex_line_configuration.lo
        powerflow/powerflow_la-triplex_line.lo
        powerflow/powerflow_la-triplex_load.lo
        powerflow/powerflow_la-triplex_meter.lo
        powerflow/powerflow_la-triplex_node.lo
        powerflow/powerflow_la-underground_line_conductor.lo
        powerflow/powerflow_la-underground_line.lo
        powerflow/powerflow_la-vfd.lo
        powerflow/powerflow_la-voltdump.lo
        powerflow/powerflow_la-volt_var_control.lo
        reliability/reliability_la-eventgen.lo
        reliability/reliability_la-init.lo
        reliability/reliability_la-main.lo
        reliability/reliability_la-metrics.lo
        residential/residential_la-appliance.lo
        residential/residential_la-clotheswasher.lo
        residential/residential_la-dishwasher.lo
        residential/residential_la-dryer.lo
        residential/residential_la-evcharger.lo
        residential/residential_la-evcharger_det.lo
        residential/residential_la-freezer.lo
        residential/residential_la-house_e.lo
        residential/residential_la-init.lo
        residential/residential_la-lights.lo
        residential/residential_la-main.lo
        residential/residential_la-microwave.lo
        residential/residential_la-occupantload.lo
        residential/residential_la-plugload.lo
        residential/residential_la-range.lo
        residential/residential_la-refrigerator.lo
        residential/residential_la-residential_enduse.lo
        residential/residential_la-solvers.lo
        residential/residential_la-thermal_storage.lo
        residential/residential_la-waterheater.lo
        residential/residential_la-zipload.lo
        tape_file/tape_file_la-tape_file.lo
        tape/tape_la-collector.lo
        tape/tape_la-file.lo
        tape/tape_la-group_recorder.lo
        tape/tape_la-metrics_collector.lo
        tape/tape_la-metrics_collector_writer.lo
        tape/tape_la-violation_recorder.lo
        tape/tape_la-histogram.lo
        tape/tape_la-loadshape.lo
        tape/tape_la-main.lo
        tape/tape_la-memory.lo
        tape/tape_la-multi_recorder.lo
        tape/tape_la-odbc.lo
        tape/tape_la-player.lo
        tape/tape_la-recorder.lo
        tape/tape_la-tape.lo
        tape/tape_la-shaper.lo
        tape_plot/tape_plot_la-tape_plot.lo
        third_party/superLU_MT/libsuperlu.la
        gridlabd
        third_party/jsonCpp/libjsoncpp.la
        assert/assert.la
        climate/climate.la
        commercial/commercial.la
        gldcore/link/engine/glxengine.la
        gldcore/link/matlab/glxmatlab.la
        gldcore/solvers/glsolvers.la
        generators/generators.la
        market/market.la
        mysql/mysql.la
        optimize/optimize.la
        tape_file/tape_file.la
        tape_plot/tape_plot.la
        connection/connection.la
        reliability/reliability.la
        residential/residential.la
        tape/tape.la
        powerflow/powerflow.la
        assert/assert.dll
        climate/climate.dll
        commercial/commercial.dll
        gldcore/link/engine/glxengine.dll
        gldcore/link/matlab/glxmatlab.dll
        gldcore/solvers/glsolvers.dll
        generators/generators.dll
        market/market.dll
        mysql/mysql.dll
        optimize/optimize.dll
        tape_file/tape_file.dll
        tape_plot/tape_plot.dll
        connection/connection.dll
        reliability/reliability.dll
        residential/residential.dll
        tape/tape.dll
        powerflow/powerflow.dll
        assert/assert.so
        climate/climate.so
        commercial/commercial.so
        gldcore/link/engine/glxengine.so
        gldcore/link/matlab/glxmatlab.so
        gldcore/solvers/glsolvers.so
        generators/generators.so
        market/market.so
        mysql/mysql.so
        optimize/optimize.so
        tape_file/tape_file.so
        tape_plot/tape_plot.so
        connection/connection.so
        reliability/reliability.so
        residential/residential.so
        tape/tape.so
        powerflow/powerflow.so
        )


if (GLD_DO_CLEANUP)
    foreach (file ${cleanup_list})
        FILE(REMOVE ${CMAKE_SOURCE_DIR}/${file})
    endforeach ()
else ()
    foreach (file ${cleanup_list})
        if (EXISTS ${CMAKE_SOURCE_DIR}/${file})
            MESSAGE(FATAL_ERROR "CMake detected files from a previous version of GridLAB-D. "
                    "These may interfere with the build process and should be removed. "
                    "To remove these files automatically, rerun CMake and set the `GLD_DO_CLEANUP` flag to `ON` "
                    "(e.g. `-DGLD_DO_CLEANUP=ON`)"
                    )
            BREAK()
        endif ()
    endforeach ()
endif ()
